package org.szgb.console.wecom.robot.web;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.szgb.console.wecom.robot.entity.WeComRobotMessage;
import org.szgb.console.wecom.robot.service.WeComRobotService;
import org.szgb.core.utils.AjaxJson;

import java.io.IOException;

@Slf4j
@RestController
@RequestMapping(value = "/wecom/robot")
@Tag(name = "企业微信机器人通知管理", description = "企业微信机器人通知模块")
public class WeComRobotController {
    private final WeComRobotService weComRobotService;

    @Autowired
    public WeComRobotController(WeComRobotService weComRobotService) {
        this.weComRobotService = weComRobotService;
    }

    @Operation(summary = "发送文本消息", description = "发送文本消息")
    @PostMapping("/sendText")
    public AjaxJson sendText(@RequestBody WeComRobotMessage.WeComRobotMessageText weComRobotMessageText, HttpServletRequest request, HttpServletResponse response) throws IOException, InterruptedException {
        weComRobotService.sendText(weComRobotMessageText.getContent(), weComRobotMessageText.getMentionedList());
        return AjaxJson.success(request, response);
    }
}
